//
//  U9LaunchManager.m
//  U9WatchGame
//
//  Created by uuu9 on 2017/6/2.
//  Copyright © 2017年 UUU9. All rights reserved.
//

#import "U9LaunchManager.h"
#import "U9CatagoryModel.h"
#import "U9VersionModel.h"
#import "U9LaunchAdvertisementModel.h"
#import "U9BetSwitchModel.h"

@implementation U9LaunchManager

+(void)getLaunchAdvertisementWithCompletionHandle:(void (^)(NSDictionary *, NSError *))complete{
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kGetLaunchAdvert]
    parameters:nil
completionHandler:^(id responseObj, NSError *error) {
    U9LaunchAdvertisementModel *model = [U9LaunchAdvertisementModel mj_objectWithKeyValues:responseObj];
    if (model.error_code != 0) {
        error = [self createError:model.error_msg];
    }
    complete(responseObj,error);
}];
}


+(void)getGuessStatusWithCompletionHandle:(void (^)(NSString *, NSError *))complete{
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kGetGuessSwitch]
   parameters:nil
completionHandler:^(id responseObj, NSError *error) {
    NSString *boo;
    @try {
        boo = responseObj[@"output"][@"status"];
    } @catch (NSException *exception) {
        boo = @"1";
    } @finally {
        complete(boo,error);
    }
}];
}




//+(void)getCatagoryWithCompletionHandle:(void (^)(U9CatagoryModel *, NSError *))complete{
//    PlistStorage *plist = [PlistStorage sharedPlistStorage];
//    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kGetClassCatagory]
//   parameters:nil
//completionHandler:^(id responseObj, NSError *error) {
//    U9CatagoryModel *model = [U9CatagoryModel mj_objectWithKeyValues:responseObj];
//    if (model.error_code != 0) {
//        error = [self createError:model.error_msg];
//        model = [U9CatagoryModel mj_objectWithKeyValues:[plist readFromPlist:@"CatagoryList"]];
//    } else if (error) {
//        model = [U9CatagoryModel mj_objectWithKeyValues:[plist readFromPlist:@"CatagoryList"]];
//    } else {
//        [plist storageToPlist:responseObj andFileName:@"CatagoryList"];
//    }
//    complete(model,error);
//}];
//
//}


+(void)getCatagoryWithCompletionHandle:(void (^)(U9CatagoryModel *, NSError *))complete{
    PlistStorage *plist = [PlistStorage sharedPlistStorage];
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kGetClassCatagory]
   parameters:nil
completionHandler:^(id responseObj, NSError *error) {
    U9CatagoryModel *model = [U9CatagoryModel mj_objectWithKeyValues:responseObj];
    if (model.error_code != 0) {
        error = [self createError:model.error_msg];
        model = [U9CatagoryModel mj_objectWithKeyValues:[plist readFromPlist:@"CatagoryList"]];
    } else if (error) {
        model = [U9CatagoryModel mj_objectWithKeyValues:[plist readFromPlist:@"CatagoryList"]];
    } else {
        [plist storageToPlist:responseObj andFileName:@"CatagoryList"];
    }
    complete(model,error);
}];

}


+(void)getBetSwitchWithCompletionHandle:(void (^)(U9BetSwitchModel *, NSError *))complete{
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kBetSwitch]
   parameters:nil
completionHandler:^(id responseObj, NSError *error) {
    U9BetSwitchModel *model = [U9BetSwitchModel mj_objectWithKeyValues:responseObj];
    if (model.error_code != 0) {
        error = [self createError:model.error_msg];
    }
    complete(model,error);
}];
    
}




+(void)checkVersionWithCompletionHandle:(void (^)(U9VersionModel *model, NSError *))complete{
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kCheckVersion]
    parameters:nil
completionHandler:^(id responseObj, NSError *error) {
    U9VersionModel *model = [U9VersionModel mj_objectWithKeyValues:responseObj];
    if (model.error_code != 0) {
        error = [self createError:model.error_msg];
    }
    complete(model,error);
}];
    
}


@end
